package cn.kjcoder.springcloud.controller;

import cn.kjcoder.springcloud.domain.JsonResult;
import cn.kjcoder.springcloud.domain.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;



/**
 * @author hkj
 * @email 1349091387@qq.com
 * @date 2021/12/20
 * 源码允许修改，并且本人十分乐意有 大佬 来对代码进行 随 意 调 教
 **/
@RestController
@Slf4j
@RequestMapping("order")
public class OrderController {

    //public static final String PAYMENT_URL = "http://localhost:8001";
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Autowired
    public RestTemplate restTemplate;

    @GetMapping("/payment/save")
    public JsonResult<Payment> save(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL + "/payment/save",payment,JsonResult.class);
    }

    @GetMapping("/payment/get/{id}")
    public JsonResult<Payment> get(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id,JsonResult.class);
    }

    /*************************************链路追踪***********************************************/
    @GetMapping("/payment/zipkin")
    public String zipkin(){
        String result = restTemplate.getForObject(PAYMENT_URL + "/payment/zipkin", String.class);
        return result;
    }

}
